<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    这是b页面
    <script>
        console.log(location.search)
        //处理传递过来的数据
        //location.search接收了
        //不管37 21 先把数据渲染出来，再对数据做处理
        //1.渲染数据
        // 先把location.search转成对象
        let str1 = location.search
        let obj1 =  changObj(str1)
        print(obj1)
        calcultor(obj1.long)
        console.log(obj1)
        //已经顺利的获取了这个参数对象
        //通过dom操作来渲染这个参数对象
      
        function changeTime(timeStramp){
            // let  timeStramp = "1627632272182";
            let  timeStr = new Date(Number(timeStramp)) 
            let year = timeStr.getFullYear()
            let month = timeStr.getMonth() + 1 <10 ? "0" + (timeStr.getMonth() + 1):timeStr.getMonth() + 1
            let day = timeStr.getDate() < 10? "0" +timeStr.getDate():timeStr.getDate()
            
            let hour = timeStr.getHours() < 10 ? "0" + timeStr.getHours():timeStr.getHours()
            let min = timeStr.getMinutes() <10 ? "0" + timeStr.getMinutes():timeStr.getMinutes()
            let sec = timeStr.getSeconds() < 10? "0" + timeStr.getSeconds():timeStr.getSeconds()
            
            console.log(year,month,day)
            return `${year}-${month}-${day}-${hour}:${min}:${sec}`
            // yy-mm-dd 最终的格式输出
        }
        function calcultor(str){
            // let str = 'mymymyalex'
            let o ={}
            for(let i=0;i<str.length;i++){
                //判断当前str[i] 是不是对象o 中的属性？
                let char = str[i]
                if(o[char]){
                    //char已经有 操作对应的属性值 + 1
                    o[char]++
                }else{
                    //给这个属性初始化为1
                    o[char] = 1;
                }
            }
            console.log(o)
            // 比较大小
            // 遍历对象的操作
            let max = 0;
            for(let key in o){
                if(max<o[key]){
                    max = o[key] //永远保持max最大的
                }
            }
            //max 去比较 对象中对应的属性值
            for(let key in  o ){
                if(max == o[key]){
                    console.log('出现最多次数的字符是',key)
                    console.log('出现最多次数是',max)
                    let div = document.createElement('div')
                    div.innerHTML = `
                                       <div>
                                          <span>
                                            出现最多次数的字符是${key}
                                          </span>
                                          <span>
                                            出现最多次数是${max}
                                          </span>
                                        </div>
                                    `
                    document.body.appendChild(div)
                }
            }
            return 
        }

        function changeMoney(money){      
            return '$' + Number(money).toLocaleString()+'.00'
        }
       
        function cover(str){
            let newStr = ""
            let num = str.length - 1;
            let head  = str[0]
            let tail = str[num]
            for(let i=0;i<=num - 2;i++){
                newStr += '*'
            }
            return head+newStr+tail
            // console.log(str)

        }
        //做渲染的功能
        function print(obj){  
            let div = document.createElement('div')
            div.innerHTML = `
                                <div>
                                    <span>姓名：</span>
                                    <span>${decodeURI(obj.uname)} ${obj.sex=="0"?"女士":"先生"}</span>
                                </div>
                                <div>
                                    <span>密码：</span>
                                    <span>${cover(obj.pwd)}</span>
                                </div>
                                <div>
                                    <span>金额：</span>
                                    <span>${changeMoney(obj.money)}</span>
                                </div>
                                <div>
                                    <span>注册事件</span>
                                    <span>${changeTime(obj.timeStramp)}</span>
                                </div>
                                <div>
                                    <span>填写的内容：</span>
                                    <span>${obj.long}</span>
                                </div>
                                
                            `
            document.body.appendChild(div)
        }

        //获取参数对象并转成对象输出
        function changObj(str){
            let obj = {}
            str  = str.slice(1)
            console.log(str)
            str.split('&').forEach(function(ele){
                // ele  "健名=键值"
                obj[ele.split('=')[0]]=ele.split('=')[1]
            })
            return obj

        }
        //2.处理数据
    </script>
</body>
</html>